package satir.card;

import java.util.ArrayList;
import java.util.Scanner;

import satir.player.Player;


/**
 * The Class AwardSECard.
 * This class generalize the type of card that would reward self esteem to player
 * 
 * @version 2.0 March 2012
 * @author Chris Chan
 */
public abstract class AwardSECard extends Card {
	
	/** The questions. */
	protected ArrayList<Question> questions;
	
	/**
	 * Instantiates a new award se card.
	 *
	 * @param name the name
	 * @param questions the questions
	 */
	public AwardSECard(String name, ArrayList<Question> questions){
		super(name);
		this.questions = questions;
	}
	
	/* (non-Javadoc)
	 * @see stair.card.Card#activateCard(stair.player.Player)
	 */
	abstract public void activateCard(Player _p);
	
	/**
	 * Use magic tool.
	 *
	 * @param player the player
	 * @param cardType the card type
	 * @return true if player is going to use magic tool
	 */
	protected boolean useMagicTool(Player player, String cardType){
		int toolIndex = 0;
		boolean isUseTool = false;
		boolean hasUsableTool = false;
		ArrayList<MagicToolCard> mtCards = player.getMtCards();
		ArrayList<MagicToolCard> usableCards = new ArrayList<MagicToolCard>();
		
		//Check if the player has usable magic tool
		for(int i=0; i<mtCards.size(); i++){
			MagicToolCard mtCardTmp = mtCards.get(i); 
			if((mtCardTmp.getTargetCard().equals(cardType)) || (mtCardTmp.getTargetCard().equals("Any"))){
				usableCards.add(mtCardTmp);
				hasUsableTool = true;
			}
		}
		if(hasUsableTool){	//player has usable tool
			Scanner sc = new Scanner(System.in);
			System.out.println("Would you like to use Magic Tools? (\"Yes\" or \"No\")");
			String userInput = sc.next();
			isUseTool = userInput.equals("Yes");
			if(isUseTool){
				System.out.println("Use which Magic Tools?");
				for(int i=0; i<usableCards.size(); i++){
					MagicToolCard mtCardTmp = usableCards.get(i);
					System.out.println((i+1)+". "+mtCardTmp.getName());
				}
				userInput = sc.next();
				toolIndex = Integer.parseInt(userInput);
				//Get the selectd tool and activate it
				MagicToolCard useMTCard = usableCards.get(toolIndex-1);
				useMTCard.activateCard(player);
				player.removeMtCard(useMTCard);
			}
		}
		return isUseTool;
	}
}
